package com.cloud.business.vo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.business.enums.ErrorType;
import com.cloud.business.enums.ResultEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@ApiModel("应答信息")
@AllArgsConstructor//全参构造器
@NoArgsConstructor//无参构造器不加上feign报错
public class TableResultVO<T> {
    @ApiModelProperty("应答消息编码:200000、成功；500000、失败；其它编码参考统一错误码文档")
    private Integer code;

    @ApiModelProperty("应答消息")
    private String msg;

    @ApiModelProperty("请求结果")
    private T data;

    @ApiModelProperty("查询总数")
    private Long total;

    /**
     * 返回信息方法
     */
    public static TableResultVO msg(ErrorType errorType) {
        return new TableResultVO(errorType.getCode(),errorType.getMsg(),null,null);
    }
    /**
     * 成功方法
     */
    public static TableResultVO success(Page page) {
        return new TableResultVO<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), page.getRecords(), page.getTotal());
    }
}
